package spring_05_aop.example.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import spring_05_aop.example.StaticAgent.MyTransaction;

public class ObjectInterceptor implements InvocationHandler{
	
	//目标类
	private Object target;
	//切面类（这里指事务类）
	private MyTransaction myTransaction;
	
	//通过构造器赋值
	public ObjectInterceptor(Object target,MyTransaction myTransaction){
		this.target = target;
		this.myTransaction = myTransaction;
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		// TODO Auto-generated method stub
		//开启事务
		this.myTransaction .before();
		//调用目标类方法
		method.invoke(this.target, args);
		this.myTransaction.after();
		return null;
	}

}
